DaqBoard2000 Series Driver For Linux email: linux@iotech.com Make sure you have a copy of the Daq Programmers Manual get it at iotech.com Please email any comments or questions to linux@iotech.com Linux Kernel version 2.4 and above. x86 based single processor machines only. Functions Currently Supported: Analog Input (using driver buffer based acquisition only - see note below) Digital IO Counter Timer Analog Output (voltage only) Functions Currently Unsupported: Waveform Analog Output Known Issues: Buffer Allocation : The buffer allocation via the Linux "mmap" call, allocates pages using the _get_free_pages call which allocates a minimum of 4096 bytes and doubles from there up to 2097152 The granularity looks like this: 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576 2097152 Keeping this in mind a call to daqAdcTransferSetBuffer with a request for a 100,000 byte buffer will result in the driver attempting to allocate 131072 bytes of memory for data storage. The extra space acquired is transparent to the user application, and the programmer need not be concerned with the extra space acquired. Repeated removal and installation of the driver module db2k.o: We are currently hunting down a memory leak which will eventually cause the insmod db2k.o command to fail after issuing the rmmod and insmod commands repeatedly. Preliminary testing indicates that this failure will occur on the fourth attempt to install the module. Workaround: Reboot! Buffer Mode usage Currently only the Driver Buffer mode of the daqAdcTransferSetBuffer call is supported. An attempt to use the DatmUserBuf flag will result in garbage data being returned or worse. Use the DatmDriverBuf flag only. And use the daqAdcTranferBufData to move your from the driverto your application. Unpacking the sources The source files and subdirectories are contained in the daqboard2000.tgz file. The root directory is DaqBoard2000 with db2kdriver, libdaqx and examples subdirectories. Copy the daqboard2000.tgz file into the directory from which you wish to work then issue the following command: tar -xvzf daqboard2000.tgz This will extract all the source files into there appropriate directories. At the command prompt type cd DaqBoard2000 to enter the new directory. Instructions from here out will assume you are working from the DaqBoard2000 directory. Building the driver * At this point, if you are not logged in as root you should issue the su root command and enter the root password as many of the commands in the following section require super-user privileges. At the command prompt type cd db2kdriver to enter the driver directory 1) Make the driver module make all 2) Make the Entries in the /dev directory make dev 3) Insert the module into the Kernel /sbin/insmod db2k.o 4) Verify module installation with the following command cat /proc/devices | more in the output of the cat command you should find the entry - 61 dboard2000 this confirms the installation of the device module dboard2000 with a major number of 61. 5) The var/log/messages file Once you have installed the module, take a look at the var/log /messages file, if the installation was successful, entries similar to the following should appear type cat /var/log/messages opus kernel: DB2K: linux_drvrint: InitializingDB2K: linux_drvrint: detect -> detected 1 boards. opus kernel: DB2K: linux_drvrint: probe -> board 0 >> vendorid : 20001616 deviceType: 22 opus kernel: DB2K: linux_drvrint: probe -> db2k pdev->irq 0, irq line 0, pin 0 opus kernel: DB2K: linux_drvrint: probe -> pci irqs not supported by card #0 opus kernel: DB2K: linux_drvrint: allocate_buffers -> readbuf 131072 bytes allocated @addr: VIRT:c0480000 BUS:480000 PHYS:480000 opus kernel: DB2K: linux_drvrint: allocate_buffers -> writebuf 131072 bytes allocated @addr: VIRT:c1440000 BUS:1440000 PHYS:1440000 opus kernel: DB2K: linux_drvrint: init_module -> Installed driver dboard2000 V0.1, MAJOR = 61 opus kernel: DB2K: linux_drvrint: init_module -> dboard2000: successfully initialized driver opus kernel: DB2K: linux_init_utils: loadFpga -> Completed If the installation of the module was unsuccessful this should be the first place to look for the reason why module installation failed, Also check the physical installation of your board and make sure the permissions on /dev/db2k/root are equal to 666 (read and write for everybody) Building the daqx library At the command prompt type cd ../libdaqx to change to the library directory. 1) Make the daqx library make libdaqx 2) Create links to the library make link Using the Examples At the command prompt type cd ../examples to change to the examples directory. ** View the example descriptions below for explanations of the various example programs. To build any of the various example files manually use the following format gcc DaqAdcEx02.cpp -DDLINUX -o DaqAdcEx02 -ldl This command line builds the Executable DaqAdcEx02 from the source file DaqAdcEx02.cpp. The source files are used across multiple operating systems so the -DDLINUX compiler flag is a necessity. The -ldl flag tells the linker that a dynamic library is used within the source. If the compilation was successful you can execute the file with the command ./DaqAdcEx02 Your Results Should look similar to this. Attempting to Connect with daqBoard2k0 daqBoard2k0 opened daqBoard2k0 Armed Hit any key to issue software trigger... Scan Triggered Scan Completed Analog ch 0 Analog ch 1 Analog ch 2 -1.954 -1.103 -0.000 0.360 -0.688 0.000 2.535 0.097 -0.000 3.367 0.835 -0.000 2.677 1.197 -0.002 0.550 0.964 -0.002 -1.810 0.244 -0.002 -3.083 -0.565 -0.002 -2.849 -1.080 -0.002 -1.087 -1.033 -0.001 1.350 -0.424 -0.000 3.074 0.388 -0.000 3.299 1.014 -0.002 1.928 1.145 -0.002 -0.456 0.696 -0.002 -2.528 -0.106 -0.002 -3.163 -0.817 -0.000 -2.290 -1.113 -0.001 -0.091 -0.803 -0.000 2.203 -0.058 -0.001 3.337 0.717 -0.001 2.930 1.170 -0.002 1.004 1.043 -0.002 -1.429 0.389 -0.003 -2.977 -0.439 -0.003 daqBoard2k0 Closed A check of the var/log/messages file should contain something similar to this: *** Viewing the Messages Log may require super_user privilages. type cat /var/log/messages opus kernel: DB2K: linux_drvrint: open -> major/minor = 61/0 opus kernel: DB2K: linux_drvrint: open -> successfully opened DBOARD2000 opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_CONFIG opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_CONFIG opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_ARM opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_DISARM opus kernel: DB2K: linux_drvrint: mmap -> user requested buffer size 4096 opus kernel: DB2K: linux_drvrint: mmap -> buffer location from init c248e000 opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_CONFIG opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_START opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_CONFIG opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_ARM opus kernel: DB2K: linux_entrypnt: entryIoctl -> DB_ADC_SOFTTRIG opus kernel: DB2K: linux_drvrint: mmap_close -> Releasing User Buffer Example Descriptions DaqAdcEx02.cpp This is 3 channel, software triggered finite acquisition using single ended inputs in bipolar mode. Upon launching, the program will wait until a key if pressed and then issue a software trigger to begin the acquisition. When the Acquisition is complete the data is scaled, formatted and output to the screen. DaqAdcEx03.cpp This is a single channel hardware start trigger, software stop trigger, finite acquisition using single ended inputs in bipolar mode. Upon launching, the program will wait until a rising voltage greater than 2.0 volts is seen on the input of channel 0. At that point 100 scans will be taken. At the end of the 100 scans the stop trigger event will be looked for. When the stop trigger event is found the daqAdcTransferBufData call will return the acquired data. the data is then scaled, formatted and output to the screen. DaqAdcEx04.cpp This is a single channel TTL start trigger, "stop on count" stop trigger, finite acquisition using single ended inputs in bipolar mode. Acquired data is stored on a disk file. Upon launching the program will wait until a TTL trigger voltage is sensed on the TTL TRIG input of the P1 connector. At that point 500 scans will be taken and the acquisition will stop. Data is stored in binary form into a file called "bindata.bin". You may compile and run the "bincvt.cpp" to view the acquired data. See the explanation of the bincvt.cpp program below. DaqAdcEx05.cpp This is single channel, immediate trigger, "stop on count" stop trigger, finite acquisition using single ended inputs in bipolar mode. This example uses an external acquisition pacer clock. ** This Example was tested using a 1Khz square wave input to the "A/I CLK" input of the P1 connector. Consult the IOtech Daq Programmers Manual and your DaqBoard2000 Users Manual to determine suitable input. Upon launching the program will trigger immediately and acquire 25 scans at the rate of the external clock input. When the Acquisition is complete the data is scaled,formatted and output to the screen. If no external clock is attached the program will issue a timeout error. DaqAdcEx06.cpp This is a 2 channel, digital pattern start trigger, digital pattern stop trigger, finite acquisition using single ended inputs in bipolar mode. Although 2 channels are configured the first is used for triggering and is not included in the output data. Upon launching the program waits for the digital pattern specified by the STARTPATTEN definition in the code. For this example input D0 on the P3 connector is used. When a HIGH is applied to D0 the acquisition will start. 20 scans will then be performed before the stop trigger event is looked for (D0 LOW). When the Acquisition is complete the data is scaled, formatted and output to the screen. DaqAdcEx07.cpp This 7 channel, immediate trigger, "stop on count" stop trigger, finite acquisition using the following: Three P2 8 bit digital channels A, B, and C The P3 16 bit digital channel D0 thru D15 The P3 CNT1 input configured as a 16 bit counter The P3 CNT0 input cascaded to CNT2 as a 32 bit counter Upon launching the program will trigger immediately and acquire 25 scans of the channels listed above. When the Acquisition is complete the data is scaled, formatted and output to the screen. DaqAdcEx08.cpp This is 2 channel, software triggered continuous acquisition using single ended inputs in bipolar mode. Upon launching, the program will wait until a key if pressed and then issue a software trigger to begin the acquisition. Acquired data is retrieved from the driver buffer via daqAdcTransferBufData function. Data is then scaled, formatted and output to the screen. The daqAdcTransferBufData is continuously called in a loop until another key is pressed to stop the acquisition. ** Notice the doubling of the buffer size in the daqAdcTransferSetBuffer function call. This is to avoid buffer over-run errors. DaqAdcEx10.cpp This is a 2 channel, immediate trigger, "stop on count" stop trigger, finite acquisition using single ended inputs with the first channel in bipolar mode and the second channel in unipolar mode. Upon launching the program will trigger immediately and acquire 15 scans. When the acquisition is complete the data is first manually scaled, formatted and output to the screen. Then using the daqCvtSetAdcRange and daqCvtLinearSetupConvert functions the data is automatically scaled, formatted and output to the screen. DaqAdcEx11.cpp This example demonstrates the use of the 4 "single step" data acquisition functions available through the libdaqx library. All the functions called in this example use single-ended inputs in bipolar mode. The first function daqAdcRd acquires 1 point from 1 channel. The second function daqAdcRdN acquires 10 points from one channel. The third function daqAdcRdScan acquires 1 point from a group of 10 channels. The fourth function daqAdcRdScanN acquires 2 points from 5 channels. When each of the above functions returns, a function within the program called printConvertedData is called to display the acquired data. DaqDigIOEx01.cpp This example sets P2 digital ports A, B and C initially in output mode and then switches to input mode. The first call to daqIOGet8255Conf with control bits set to 0,0,0,0 retrieves the configuration word need to set P2 Ports A, B and the Upper and Lower nibbles of port C as outputs. This configuration word is then written to the 8255 with the next daqIOWrite function configuring the ports for output. The values that are to be written are then output to the screen. In the subsequent 3 daqIOWrite function calls digital values are the written to their respective ports. The next call to daqIOGet8255Conf with control bits set to 1,1,1,1 gets the configuration word needed to set all ports to be inputs. The next call to daqIOWrite sets them to inputs. Three calls are then made to daqIORead and the values of the ports are retrieved and displayed. DaqDigIOEx02.cpp This example sets digital Port P3 initially in output mode the switches to input mode. The first call to daqIOWrite sets the P3 16bit digital port in output mode. The word that is to be applied to the port is then displayed and the second call to daqIOWrite writes the value to the port. The third call to daqIOWrite configures the port for input mode. daqIORead is then called to retrieve the ports value. It is the printed on the screen. DaqTmrEx01.cpp This Example uses daqSetOption calls to generate Square wave outputs on the P3 TMR0 and TMR1 connections. The first two daqSetOption calls sets the frequency divisors for TMR0 and TMR1 respectively. The third call to daqSetOption turns the timer controls on simultaneously. A message is then displayed and the output will continue until is pressed. The final call to daqSetOption turns the timer outputs off. DaqDacEx01.cpp This Example uses the daqDacSetOuputMode and daqDacWtMany calls to generate voltage outputs on the P3 CH0 and CH1 connections. In the for loop the call to daqDacSetOuputMode configures the Daqboard to use the local P3 port (DddtLocal) and use voltage output mode (DdomVoltage) for the two channels. The daqDacWtMany function is then given the device types, channels and counts (converted from voltages) to ouput along with the number of channels. This call starts the voltage output. The output will continue until a enter is pressed. A second call to daqDacWtMany with counts that corresspond to 0 volt output is called to halt the output. bincvt.cpp This program scales and outputs the binary file data generated by example DaqAdcEx04.cpp. to both the screen and a text file. This program is currently configured to convert the two channels of data generated by DaqAdcEx04.cpp which is found in the bindata.bin file. You can easily modify the source to use different channel or gain combinations.